package com.wsl.server.configuration;

import com.wsl.server.AppService;
import com.wsl.server.AppServiceImpl;
import com.wsl.server.AuthInterceptor;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;


import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;


/**
 * @Author:wangshuliang
 * @Description:
 * @Date:Created in 16:55 2019/5/21
 * @Modified by:
 */
@Configuration
public class CxfConfig {
    /**
     * 默认servlet路径/*,如果覆写则按照自己定义的来
     * @return
     */
    @Bean
    public ServletRegistrationBean dispatcherServlet(){
        return new ServletRegistrationBean(new CXFServlet(),"/services/*");
    }
    @Bean(name= Bus.DEFAULT_BUS_ID)
    public SpringBus springBus(){
        return new SpringBus();
    }

    /**
     * 把实现类交给Spring管理
     * @return
     */
    @Bean
    public AppService appService(){
        return new AppServiceImpl();
    }

    //终端路径
    @Bean
    public Endpoint endpoint(){
        EndpointImpl endpoint = new EndpointImpl(springBus(),appService());
       // endpoint.getInInterceptors().add(new AuthInterceptor());
        endpoint.publish("/user");
        return endpoint;
    }
}
